# -*- coding: utf-8 -*-
# @Time    : 2018/4/17 22:03
# @Author  : Soft
# @File    : __init__.py.py
# @Software: PyCharm
# #Desc    : excel表格工具类
import os

import xlrd
import xlwt

white = xlwt.easyxf()
yellow = xlwt.easyxf('pattern: pattern solid, fore_colour yellow;')
red = xlwt.easyxf('pattern: pattern solid, fore_colour red;')
blue = xlwt.easyxf('pattern: pattern solid, fore_colour blue;font: color white;')


def getWriteBook():
    return xlwt.Workbook()


def getReadBook(filename):
    temp = __path__[0] + os.path.sep + "temp" + os.path.sep + filename
    return xlrd.open_workbook(temp)


def deleteFile(filename):
    temp = __path__[0] + os.path.sep + "temp" + os.path.sep + filename
    if os.path.exists(temp):
        os.remove(temp)
    return temp


def saveTempFile(book, filename):
    """
    保存生成的execl文件，保存前先删除临时文件
    :param book: workbook实例
    :param filename: 文件名
    :return: 临时文件全路径
    """
    temp = deleteFile(filename)
    book.save(temp)
    return temp
